
 $(function(){
   var showTitle=localCache.getSessionItem('showartitle'),loadPrompt;
   var app_key=localCache.getSessionItem('account_identifer'),
   sign=localCache.getSessionItem('sign'),
   timestamp=localCache.getSessionItem('timestamp'),
   cust_account=localCache.getSessionItem('periphery_account');
   
   if(!showTitle){//不需要展示标题、返回、充值按钮
     $('#header').css('display','none');
     $('#accountInfo').css('margin-top',0);
     $('#alipay').css('display','none');
     $('#card').css('display','none');
     $('#moredetail').css('display','none');
   }else{
	   var isAdmin=localCache.getSessionItem('isAdmin');
	   if(isAdmin==='true'){/**管理员登录**/
		   var isShowAlipay=localCache.getSessionItem('isShowAlipay');
		   if('false'===isShowAlipay){
			   isShowAlipay = false;
		   }
		   if(isShowAlipay){//不展示支付宝充值
			   $('#alipay').css('display','none');
		   }  
	   }else{
		     $('#alipay').css('display','none');
		     $('#card').css('display','none');
	   }
	   $('#more1').on('click',function(){
		      var html='<div id="more_alert_content1" ><a id="consumedetail"><dt><img src="images/mingxi1.png" width="60" height="60"></dt>';
		      html+='<dd>通话明细</dd></a><a id="chargedetail"><dt><img src="images/mingxi2.png" width="60" height="60"></dt>';
		      html+='<dd>充值明细</dd></a>';
		      var isShowUnionAccount=localCache.getSessionItem('isShowUnionAccount');
		      if(isShowUnionAccount==='true')
		    	  html+='<a id="unionaccount"><dt><img src="images/third.png" width="60" height="60"></dt><dd>合并账户</dd></a>';
		      html+='</div><i class="arrow_up"></i>';
		      new NavigationPrompt(html);
		      if(isShowUnionAccount==='false'){
		    	  $('#more_alert_content1').css('width','200');
		      }		      
		});
		  
		  $(document.body).on('click','#chargedetail',function(){  
		    location.assign('recharge_details.html');
		  });
		  $(document.body).on('click','#consumedetail',function(){
		    location.assign('history_detail.html');
		  });
		  $(document.body).on('click','#unionaccount',function(){
			  location.assign('union_account.html?showHeader=0&app_key='+app_key+'&cust_account='+cust_account+'&sign='+sign+'&timestamp='+timestamp);
		  });

		  $('#back').on('click',function(){
			     if(meetCache.hasMeetStorage()){
			       location.assign('call_meeting.html');
			     }else{
			       location.assign('starting.html');
			     }
			  });
   }
  var url= localCache.getSessionItem('account_resourcesinfo_url');
  $('#companyName').html(localCache.getSessionItem('companyName'));

   $.ajax({
      type: "get",
      url: url,
      dataType: "jsonp",  
      data:{
        cust_account:localCache.getSessionItem('periphery_account'),
        app_key:localCache.getSessionItem('account_identifer')
      },
      jsonp: "callback",
      success: function(data){
        if(data){
          if(data['flag']=='0000'){
             var rs=data.data,mpty=0,voice=0,dial=0,details=[],ele;
             var resourcesInfo={
            	'voice':0,
            	'dial':0,
            	'mpty':0
             };           
             $('#account').html(rs.account_data+'元');
             for (var i = 0; i < rs.resource_data.length; i++) {
                ele=rs.resource_data[i];
            	var rType=ele.product_key.toLowerCase();
            	if(rType==='voice'||rType==='dial'||rType==='mpty'){
                    details.push({
                        resuource_num:ele.resuource_num,
                        measure_type:ele.measure_type,
                        buy_type:ele.buy_type,
                        end_time:ele.end_time,
                        type:rType
                      });
                    resourcesInfo[rType]=resourcesInfo[rType]+ele.resuource_num;  
            	}            
             };
             $('#mpty').html(resourcesInfo.mpty); 
             $('#voice').html(resourcesInfo.voice);
             $('#dial').html(resourcesInfo.dial);
             if(showTitle){//展示标题
                 $('#moredetail').on('click',function(){
                     location.assign('giving_record.html?data='+encodeURI(JSON.stringify(details)));
                 });
             }
          }
        }  
      },
      complete:function(xhr,status){
          if(loadPrompt){
            loadPrompt.close();
            loadPrompt=null;
          }
      },
      beforeSend:function(){
          loadPrompt=new LoadPrompt('正在获取账户信息，请稍后...');           
      },
      error: function(){
       
      }
  });
	  
 });
 
	
